package com.example.mapboxdemo;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.mapbox.bindgen.Value;
import com.mapbox.maps.MapView;
import com.mapbox.maps.MapboxMap;
import com.mapbox.maps.Style;
import com.mapbox.maps.StyleObjectInfo;
import com.mapbox.maps.StylePropertyValue;

import java.util.List;

public class QueryActivity extends AppCompatActivity {
    private MapView mapView;
    private MapboxMap mapboxMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_query);
        mapView = findViewById(R.id.queryMapView);
        mapView.getMapboxMap().loadStyleUri(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {
            @Override
            public void onStyleLoaded(@NonNull Style style) {
//                mapView.getPlugin(Plugin.MAPBOX_GESTURES_PLUGIN_ID);
                List<StyleObjectInfo> layers = style.getStyleLayers();
                for (int i = 0; i < layers.size(); i++) {
                    Log.e("TAG", layers.get(i).getId());
                    Log.e("TAG", layers.get(i).getType());
                }

                Button button = findViewById(R.id.hide);
                button.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        StylePropertyValue value = style.getStyleLayerProperty("building", "visibility");
                        Log.e("测试", value.getValue().toString());
                        if ("visible".equals(value.getValue().toString())) {
                            style.setStyleLayerProperty("building", "visibility", Value.valueOf("none"));
                            style.setStyleLayerProperty("building-outline", "visibility", Value.valueOf("none"));
                        } else {
                            style.setStyleLayerProperty("building", "visibility", Value.valueOf("visible"));
                            style.setStyleLayerProperty("building-outline", "visibility", Value.valueOf("visible"));
                        }
                    }
                });
                Button button2 = findViewById(R.id.color);
                button2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        style.setStyleLayerProperty("building", "fill-color", Value.valueOf("#00ff00"));
                        style.setStyleLayerProperty("building-outline", "line-color", Value.valueOf("#ff0000"));
                    }
                });
            }
        });
    }
}